package com.guosifan.controller;

import com.guosifan.entity.Menu;
import com.guosifan.entity.Type;
import com.guosifan.repository.MenuRepository;
import com.guosifan.repository.TypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuRepository menuRepository;

    @Autowired
    private TypeRepository typeRepository;

    @GetMapping("/findAll")
    public List<Menu> findAll(@RequestParam int page, @RequestParam int limit){
        return menuRepository.findAll(page, limit);
    }

    @GetMapping("/count")
    public int count() {
        return menuRepository.count();
    }

    @GetMapping("/deleteById/{id}")
    public int deleteById(@PathVariable int id){
        return menuRepository.deleteById(id);
    }

    @GetMapping("/findTypes")
    public List<Type> findTypes(){
         return typeRepository.findTypes();
    }

    @PostMapping("/save")
    public int save(@RequestBody Menu menu){
        int num = menuRepository.save(menu);
        return num;
    }






}
